package com.example.ams.repository;

import com.example.ams.entity.ShiftSetting;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.Optional;

/**
 * 班次设置数据访问层
 * Shift Setting Repository
 */
@Repository
public interface ShiftSettingRepository extends JpaRepository<ShiftSetting, Long> {

    /**
     * 查询最新的生效班次
     */
    Optional<ShiftSetting> findFirstByOrderByEffectiveDateDesc();

    /**
     * 根据生效日期查询班次（用于获取指定日期的有效班次）
     */
    @Query("SELECT s FROM ShiftSetting s WHERE s.effectiveDate <= :date ORDER BY s.effectiveDate DESC")
    Optional<ShiftSetting> findEffectiveShiftByDate(@Param("date") Date date);
}

